#!/bin/bash
# prerm script for system-kernel
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <prerm> \`remove'
#        * <old-prerm> \`upgrade' <new-version>
#        * <new-prerm> \`failed-upgrade' <old-version>
#        * <conflictor's-prerm> \`remove' \`in-favour' <package> <new-version>
#        * <deconfigured's-prerm> \`deconfigure' \`in-favour'
#          <package-being-installed> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    remove|upgrade|deconfigure)
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/misc/amd64/edonr
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/misc/amd64/md5
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/misc/amd64/sha1
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/misc/amd64/sha2
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/misc/amd64/skein
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/socketmod/amd64/icmp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/socketmod/amd64/rts
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/socketmod/amd64/tcp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/socketmod/amd64/udp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/arp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/icmp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/ip
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/ipsecah
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/ipsecesp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/keysock
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/tcp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/strmod/amd64/udp
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/sys/amd64/autofs
	[ "$ZONEINST" = "1" ] || rm -f $BASEDIR/kernel/sys/amd64/rpcmod
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT cpunex )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT mpt )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT pci_pci )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT mc-amd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT intel_nb5000 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT intel_nhm )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT intel_nhmex )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT vgatext )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT pcieb )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT kb8042 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT mouse8042 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sgen )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT nulldriver )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT st )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT pseudo )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT scsi_vhci )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT bridge )
	[ "$ZONEINST" = "1" ] || (grep -c "'bridge 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -p 'read_priv_set=net_rawaccess write_priv_set=net_rawaccess' -m 'bridge 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT llc1 )
	[ "$ZONEINST" = "1" ] || (grep -c "'llc1 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'llc1 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ptm )
	[ "$ZONEINST" = "1" ] || (grep -c "'ptmx 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'ptmx 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT simnet )
	[ "$ZONEINST" = "1" ] || (grep -c "'simnet 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'simnet 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT tl )
	[ "$ZONEINST" = "1" ] || (grep -c "'ticlts 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'ticlts 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || (grep -c "'ticots 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'ticots 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || (grep -c "'ticotsord 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'ticotsord 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT vnic )
	[ "$ZONEINST" = "1" ] || (grep -c "'vnic 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null && update_drv -n  -d $BASEDIR_OPT  -m 'vnic 0666 root sys' clone)
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT acpi_drv )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT aggr )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT arp )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT bl )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT cn )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT conskbd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT consms )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT cpuid )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT crypto )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT cryptoadm )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT devinfo )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT dld )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT dlpistub )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT dump )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT eventfd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT fssnap )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT i8042 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT icmp )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT icmp6 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT inotify )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ip )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ip6 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ipnet )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ippctl )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ipsecah )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ipsecesp )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT iptun )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT iwscn )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT keysock )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT kmdb )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ksensor )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT kstat )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ksyms )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT lofi )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT log )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT logindmux )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT mm )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT openeepr )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT options )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT physmem )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT poll )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT power )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ptc )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT pts )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ptsl )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ramdisk )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT random )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT rts )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sad )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT signalfd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT smbios )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT softmac )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT spdsock )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sy )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sysevent )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT sysmsg )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT tcp )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT tcp6 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT timerfd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT tzmon )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ucode )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT udp )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT udp6 )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT ufm )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT vnd )
	[ "$ZONEINST" = "1" ] || ( rem_drv -n $BASEDIR_OPT wc )
	
    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument '$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

